import 'package:flutter/material.dart';
import './res/listDate.dart';

//ListView列表组件
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Card组件 -- 案例'),
          backgroundColor: Colors.pink[100],
        ),
        body: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  List<Widget> initCardData(){
    var temp = listDate.map((value) {
      return Card(
          margin: EdgeInsets.all(10),
          elevation: 10,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadiusGeometry.circular(10),
          ),
          child: Column(
            children: [
              AspectRatio(
                aspectRatio: 16 / 9,
                child: Image.network(
                  '${value['imageUrl']}',
                  fit: BoxFit.cover,
                ),
              ),
              ListTile(
                leading: ClipOval(
                  child: Image.network(
                    '${value['imageUrl']}',
                    width: 50,
                    height: 50,
                    fit: BoxFit.cover,
                  ),
                ),
                title: Text('${value['title']}'),
                subtitle: Text('${value['date']}'),
              ),
            ],
          ),
        );
    });
      return temp.toList();
  }

  @override
  Widget build(BuildContext context) {
    // return ListView(
    //   children: [
    //     Card(
    //       margin: EdgeInsets.all(10),
    //       elevation: 10,
    //       shape: RoundedRectangleBorder(
    //         borderRadius: BorderRadiusGeometry.circular(10),
    //       ),
    //       child: Column(
    //         children: [
    //           AspectRatio(
    //             aspectRatio: 16 / 9,
    //             child: Image.network(
    //               'https://www.itying.com/images/flutter/1.png',
    //               fit: BoxFit.cover,
    //             ),
    //           ),
    //           ListTile(
    //             leading: ClipOval(
    //               child: Image.network(
    //                 'https://www.itying.com/images/flutter/5.png',
    //                 width: 50,
    //                 height: 50,
    //                 fit: BoxFit.cover,
    //               ),
    //             ),
    //             title: Text('牛哞哞'),
    //             subtitle: Text('25块钱一斤'),
    //           ),
    //         ],
    //       ),
    //     ),
    //     Card(
    //       margin: EdgeInsets.all(10),
    //       elevation: 10,
    //       shape: RoundedRectangleBorder(
    //         borderRadius: BorderRadiusGeometry.circular(10),
    //       ),
    //       child: Column(
    //         children: [
    //           AspectRatio(
    //             aspectRatio: 16 / 9,
    //             child: Image.network(
    //               'https://www.itying.com/images/flutter/3.png',
    //               fit: BoxFit.cover,
    //             ),
    //           ),
    //           ListTile(
    //             leading: AspectRatio(
    //               aspectRatio: 1/1,
    //               child: Image.network(
    //                 'https://www.itying.com/images/flutter/3.png',
    //                 fit: BoxFit.cover,
    //               ),
    //               ),
    //             title: Text('牛哞哞'),
    //             subtitle: Text('25块钱一斤'),
    //           ),
    //         ],
    //       ),
    //     ),
    //     Card(
    //       margin: EdgeInsets.all(10),
    //       elevation: 10,
    //       shape: RoundedRectangleBorder(
    //         borderRadius: BorderRadiusGeometry.circular(10),
    //       ),
    //       child: Column(
    //         children: [
    //           AspectRatio(
    //             aspectRatio: 16 / 9,
    //             child: Image.network(
    //               'https://www.itying.com/images/flutter/3.png',
    //               fit: BoxFit.cover,
    //             ),
    //           ),
    //           ListTile(
    //             leading: CircleAvatar(
    //               radius: 25,//半径
    //               backgroundImage: NetworkImage(
    //                 'https://www.itying.com/images/flutter/4.png',
    //               ),
    //             ),
    //             title: Text('牛哞哞'),
    //             subtitle: Text('25块钱一斤'),
    //           ),
    //         ],
    //       ),
    //     ),
    //   ],
    // );
  
    return ListView(
      children: initCardData(),
    );
  }

  //页面上显示一个容器  宽度是屏幕的宽度  高度是宽度的一半
}
